package com.zb.jnlxc.dao;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import com.ZLHW.base.dao.DAO;
import com.zb.jnlxc.model.LiaoKuang;
import com.zb.jnlxc.model.ProductDetail;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-8-16
 * Time: 下午4:00
 * To change this template use File | Settings | File Templates.
 */
@Component
public class LiaoKuangDAO extends DAO<LiaoKuang, Integer> {
    @Resource
    ProductProcessDAO        productProcessDAO;

    @Resource
    private ProductDetailDAO productDetailDAO;

    public LiaoKuang getBycode(String code) {
        List<LiaoKuang> list = getByColumn("code", code);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        } else {
            return null;
        }
    }

    /**
     * 获取料框理论重量
     * @param liaoKuangId
     * @return
     */
    public Integer getLiaoKuangWeight(Integer liaoKuangId) {
        List<ProductDetail> productDetails = productDetailDAO.getDetailByLiaoKuang(liaoKuangId);
        int weight = 0;
        for (ProductDetail productDetail : productDetails) {
            weight += productDetail.getCompWeight();
        }
        return weight;
    }

}
